﻿using Halcon二次开发.Controller.趋势图工具;
using Halcon二次开发.Model;
using Halcon二次开发.Model.储放所有单例.储存每个单例界面;
using Halcon二次开发.Model.配置信息;
using Halcon二次开发.Tools;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.Controller.监视磁盘
{
    public class Monitordisk
    {
        /// <summary>
        /// ///删除本地D:盘的图片数据
        /// </summary>
        /// <returns>是否可以删除</returns>
        public bool GetMonitorSize()
        {
            string strs = "D:";
            try
            {
                DriveInfo driveInfo = new DriveInfo(strs);
                if (driveInfo.IsReady)
                {
                    long totalSize = driveInfo.TotalSize;
                    long availableFreeSpace = driveInfo.AvailableFreeSpace;

                    double totalSizeInGB = totalSize / (1024 * 1024 * 1024);
                    double availableFreeSpaceInGB = availableFreeSpace / (1024 * 1024 * 1024);
                    double proportionGB = availableFreeSpaceInGB / totalSizeInGB * 100;
                    //磁盘占比80%就要删除文件了
                    if (proportionGB> int.Parse(PathConfig.GetSingle().DiskValue))
                    {
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                (FormDb.Db["Form1"] as Form1).textBox1.AppendText("监视磁盘数据大小错误" + ":" + ex.Message + "\r\n");
                return false;
            }
            return false;
        }
    }
}
